package org.example.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@RestController
public class OrderDo {
    // mono 表示一个对象, 多个对象是 flux
    @RequestMapping("order")
    Mono<String> order(ServerWebExchange exchange){
        int port = exchange.getRequest().getLocalAddress().getPort();
        return Mono.just("order " + port);
    }

    @Autowired
    WebClient.Builder builder;

    @RequestMapping("fromIndex")
    Mono<String> index(){
        return builder.build().get()
                .uri("http://cloud-index/index")
                .retrieve()
                .bodyToMono(String.class);
    }
}
